package com.booby.javabase.enums;

/**
 * 功能描述: 接口内枚举
 *
 * @author: lizt
 * @date: 2019-06-30 10:23
 **/

public interface App {

    // 定义常量
    String version="1.0";

    enum Company{

        /**
         * 公司定义
        **/
        XIAOMI(1, "小米"),
        HUAWEI(2, "华为"),
        APPLE(3, "苹果")
        ;

        Company(int id, String name) {
            this.id = id;
            this.name = name;
        }

        public static String getCompanyName(int id){

            if (0 > id){
                return null;
            }
            for (Company item : Company.values()){
                if (item.getId() == id){
                    return item.getName();
                }
            }
            return null;
        }

        private int id;
        private String name;

        public int getId() {
            return id;
        }

        public void setId(int id) {
            this.id = id;
        }

        public String getName() {
            return name;
        }

        public void setName(String name) {
            this.name = name;
        }
    }

}

class AppTest{
    public static void main(String[] args) {

        int id = 3;

        // 接口内部枚举值应用实例 接口名.枚举类名.枚举名.属性名
        if (App.Company.APPLE.getId() == id){
            System.out.println("公司名称，Id:" + id + " name:" + App.Company.APPLE.getId());
        }

    }
}
